Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format fromBlock param on resubscription #3596

Merged
merged 3 commits into from
Jun 25, 2020
Merged

format fromBlock param on resubscription #3596

merged 3 commits into from
Jun 25, 2020

Conversation

epiccoolguy
Copy link
Contributor

Description

Added use of inputBlockNumberFormatter to ensure fromBlock is formatted properly when resubscribing. Currently when resubscribing, the plain incremented number field is put into the RPC call.

The JSON-RPC docs mention that values like fromBlock should be hex encoded. I ran into an issue where Besu will return "Invalid Params" when web3 passes in the plain number value when reconnecting on a flaky WS connection: hyperledger/besu#1088.

I'm not familiar with the web3 codebase, so it would be great if someone could point me in the right direction for adding/updating tests.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have selected the correct base branch.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • Any dependent changes have been merged and published in downstream modules.
  • I ran npm run dtslint with success and extended the tests and types if necessary.
  • I ran npm run test:unit with success.
  • I ran npm run test:cov and my test cases cover all the lines and branches of the added code.
  • I ran npm run build-all and tested the resulting files from dist folder in a browser.
  • I have updated the CHANGELOG.md file in the root folder.
  • I have tested my code on the live network.
  • I have checked the Deploy Preview and it looks correct.

@coveralls
Copy link

coveralls commented Jun 22, 2020

Coverage Status

Coverage increased (+0.003%) to 90.16% when pulling e7c69fb on epiccoolguy:hotfix/incorrect-resubscribe-formatting into 4558b27 on ethereum:1.x.

@cgewecke cgewecke self-requested a review June 22, 2020 13:36
Copy link
Collaborator

@cgewecke cgewecke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this @epiccoolguy!

What do you think about moving the fix into the re-subscription logic that comes slightly earlier than where you've currently placed it?

https://github.com/ethereum/web3.js/blob/4558b27f63277e503aa4575b08c8fd99c6ebb7d5/packages/web3-core-subscriptions/src/subscription.js#L226-L231

It looks like the bug is introduced here, when lastBlock gets assigned an output formatted blockNumber

https://github.com/ethereum/web3.js/blob/4558b27f63277e503aa4575b08c8fd99c6ebb7d5/packages/web3-core-subscriptions/src/subscription.js#L292-L293

...so this only affects resubscriptions (as you've noted).

Re: tests - this looks ok to me without an additional test. There is a logs backfilling test here which hits these lines but it's only running vs. ganache (which must be less strict about the RPC spec than besu).

@cgewecke cgewecke added 1.x 1.0 related issues Bug Addressing a bug labels Jun 22, 2020
…fering with its presence check"

This reverts commit a629577.
@epiccoolguy
Copy link
Contributor Author

Hey @cgewecke!

I initially added the formatting up there, but was worried about isFinite taking a number type value, but after reading the docs, I found out it'll convert it to number if required: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite

I'll revert it back to formatting on assignment.

If it's not necessary to test the output being formatted properly, I'd leave the PR as is.

Copy link
Collaborator

@cgewecke cgewecke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet! LGTM 💯

@ryanio
Copy link
Collaborator

ryanio commented Jun 25, 2020

Thanks @epiccoolguy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues Bug Addressing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants